package com.lxy.thread;

import org.json.JSONException;
import org.json.JSONObject;

import android.os.Handler;
import android.os.Message;
import android.util.Log;

import com.lxy.data_bean.RealTime_Weather_bean;
import com.lxy.util.MyUrl;

public class Thread_realTime extends Thread{
	private String url;
	private Handler h;
	public Thread_realTime(String url,Handler h){
		this.url=url;
		this.h=h;
	}
	
	@Override
	public void run() {
		JSONObject weatherdata=null;
		JSONObject infodata=null;
		String data=MyUrl.getDocumentAt(url);
//		System.out.println("data->"+data);
		try {
			 weatherdata=new JSONObject(data);
			 infodata= (JSONObject)  weatherdata.get("weatherinfo");
		} catch (JSONException e) {
			e.printStackTrace();
		}
		
		RealTime_Weather_bean realTimeBean=new RealTime_Weather_bean();
		
		try {
			realTimeBean.setId(infodata.getString("cityid"));
			realTimeBean.setSd(infodata.getString("SD"));
			realTimeBean.setTempretrue(infodata.getString("temp"));
			realTimeBean.setWind(infodata.getString("WD"));
			realTimeBean.setWind_level(infodata.getString("WS"));
			realTimeBean.setUpdate_time(infodata.getString("time"));
		} catch (JSONException e) {
			e.printStackTrace();
		}
//			Log.i("info:",realTimeBean.toString());
		Message msg=Message.obtain();
		msg.what=1;
		msg.obj=realTimeBean;
		h.sendMessage(msg);
	}
	
	
}
